package com.example.springmvceasybuy.service;


import com.example.springmvceasybuy.entity.News;
import com.example.springmvceasybuy.mapper.NewsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.AttributedString;
import java.util.List;

@Service
public class NewsService {

    @Autowired  // 由spring注入属性：ioc
    NewsMapper newsMapper;
    public News selectByid(int id){
        return this.newsMapper.selectById(id);
    }
    public int update(News news){
        return newsMapper.update(news);
    }
    public int delete(int id){
        return newsMapper.delete(id);
    }
    public int doinsert(News news){
        System.out.println("news对象"+news);
        return newsMapper.insert(news);
    }
    public News selectbyid(int id){
        return newsMapper.selectById(id);
    }

    /**
     * 分页查询
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public PageInfo<News> selectAllByPage(String title,int pageIndex,int pageSize){
         //设置分页页面,每页记录数
        PageHelper.startPage(pageIndex,pageSize);
        //执行查询
        List<News> news=newsMapper.selectAll(title);
        //封装一个PageInfo对象,并返回
        PageInfo<News> pageInfo=new PageInfo<>(news);
        return pageInfo;
    }
}
